home *** CD-ROM | disk | FTP | other *** search
/ Czech Logic, Card & Gambling Games / Logické hry.iso / hry / Fish Fillets / script / experiments / code.lua next >
Text File  |  2005-07-16  |  44KB  |  1,212 lines

  1.  
  2. file_include("script/"..codename.."/prog_pld.lua")
  3.  
  4. -- -----------------------------------------------------------------
  5. -- Init
  6. -- -----------------------------------------------------------------
  7. local function prog_init()
  8.     initModels()
  9.     sound_playMusic("music/rybky05.ogg")
  10.     local pokus = getRestartCount()
  11.  
  12.     local tubes = {}
  13.     for i = 0, 15 do
  14.         tubes[i] = getModelsTable()[zkum.index + i]
  15.     end
  16.  
  17.  
  18.     -- -------------------------------------------------------------
  19.     local function prog_init_room()
  20.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  21.  
  22.         room.uvod = 0
  23.         if pokus > 15 then
  24.             room.uvod = random(2)
  25.         end
  26.         room.pokusy = 0
  27.         room.bojidole = 0
  28.         room.nerus = math.floor(pokus / 2)
  29.         room.hnerus = 0
  30.         if random(10) < pokus then
  31.             room.zij = 1
  32.         else
  33.             room.zij = 0
  34.         end
  35.         room.kdy = random(1000 * pokus)
  36.         room.kdy2 = random(2000 * pokus)
  37.         if random(20) < pokus then
  38.             room.pldicim = 1
  39.         else
  40.             room.pldicim = 0
  41.         end
  42.         room.pldiciv = 0
  43.         room.kouk = 0
  44.         room.fuja = -42
  45.         room.ruk = 0
  46.         room.zku = 0
  47.         room.nep = 0
  48.         room.vic = 0
  49.         room.mrt = 0
  50.         if math.mod(pokus, 3) > 0 then
  51.             room.nedobre = 0
  52.         else
  53.             room.nedobre = 1
  54.         end
  55.         room.jej = 0
  56.         room.kolem = 0
  57.  
  58.         return function()
  59.             if no_dialog() and isReady(small) and isReady(big) then
  60.                 if room.uvod == 0 then
  61.                     room.uvod = 1
  62.                     addm(random(42) + 14, "bank-m-labolator"..(1 + random(3)))
  63.                     if pokus > random(5) and random(4) == 1 then
  64.                         room.pokusy = 1
  65.                         addv(10, "bank-v-pokusy"..(1 + random(2)))
  66.                     end
  67.                 end
  68.                 if room.bojidole == 0 and small.Y > 26 and small.X < 20 then
  69.                     room.bojidole = 1
  70.                     addm(10, "bank-m-bojim")
  71.                     if random(3) ~= 1 then
  72.                         addm(10, "bank-m-ocicka")
  73.                     end
  74.                     if random(3) ~= 1 then
  75.                         addv(15, "bank-v-pomoc")
  76.                     end
  77.                 end
  78.                 if game_getCycles() == room.kdy2 then
  79.                     if random(5) < 3 then
  80.                         addm(20, "bank-m-prohlednout")
  81.                         addv(22, "bank-v-vypad"..(1 + random(2)))
  82.                     else
  83.                         addm(20, "bank-m-tvorove")
  84.                     end
  85.                 end
  86.                 if room.pldicim == 0 and small.X > 27 and small.Y < 17 then
  87.                     addm(8, "bank-m-nesetkala")
  88.                     room.pldicim = 1
  89.                 end
  90.                 if room.pldiciv == 0 and big.X > 27 and big.Y < 17 then
  91.                     addv(25, "bank-v-mnozeni")
  92.                     room.pldiciv = 1
  93.                 end
  94.                 if room.kouk == 0 and small.Y > 26 and small.X + 1 <= oka.X then
  95.                     room.kouk = 1
  96.                     addm(2, "bank-m-kouka")
  97.                 end
  98.                 if room.fuja + 50 < game_getCycles() then
  99.                     if lahvac.rozbit == 10 and dist(small, lahvac) < 4 or oka.dir ~= dir_no and dist(small, oka) < 4 then
  100.                         addm(5, "bank-m-fuj")
  101.                         room.fuja = game_getCycles()
  102.                     end
  103.                 end
  104.                 if room.ruk == 0 and ruka.cinnost == 2 then
  105.                     room.ruk = 1
  106.                     addm(12, "bank-m-nervozni")
  107.                 end
  108.                 if room.zku == 0 then
  109.                     pom2 = 0
  110.                     for key, tube in pairs(tubes) do
  111.                         if dist(small, tube) < 2 then
  112.                             pom2 = 1
  113.                         end
  114.                     end
  115.                     if pom2 == 1 then
  116.                         room.zku = 1
  117.                         addm(7, "bank-m-zkumavka")
  118.                     end
  119.                 end
  120.                 if room.kolem == 0 and no_dialog() and room.kouk + room.zku + room.ruk + room.pldicim + room.pldiciv + room.bojidole + room.jej + room.zij + room.uvod + room.pokusy + room.nep + room.mrt + room.nedobre > 7 then
  121.                     room.kolem = 1
  122.                     addm(42, "bank-m-hlavakolem")
  123.                 end
  124.                 if room.nep == 0 and big.X == 40 and big.Y > 13 then
  125.                     room.nep = 1
  126.                     addv(4, "bank-v-neproplavu"..(1 + random(2)))
  127.                 end
  128.                 if room.vic < 2 and math.mod(game_getCycles(), 8) == 1 then
  129.                     pom2 = 0
  130.                     for key, model in pairs(getModelsTable()) do
  131.                         if model.Y < 21 and model.Y > 17 and model.X > 14 and model.X < 29 then
  132.                             pom2 = pom2 + 1
  133.                         end
  134.                     end
  135.                     if room.vic == 0 and pom2 == 5 then
  136.                         addv(5, "bank-v-nahazet")
  137.                         room.vic = room.vic + 1
  138.                     end
  139.                     if room.vic == 1 and pom2 == 7 then
  140.                         addv(5, "bank-v-jeste")
  141.                         room.vic = room.vic + 1
  142.                     end
  143.                 end
  144.                 if room.mrt == 0 and dist(small, kostra) < 3 then
  145.                     room.mrt = 1
  146.                     if random(3) ~= 1 then
  147.                         addm(1, "bank-m-mrtvolka")
  148.                     end
  149.                     switch(random(5)){
  150.                         [1] = function()
  151.                             addm(9, "bank-m-prehnal1")
  152.                         end,
  153.                         [2] = function()
  154.                             addm(9, "bank-m-prehnal1")
  155.                         end,
  156.                         [3] = function()
  157.                             addm(9, "bank-m-prehnal2")
  158.                         end,
  159.                         [4] = function()
  160.                             addm(9, "bank-m-prehnal2")
  161.                         end,
  162.                     }
  163.                 end
  164.                 if room.nedobre == 0 and lahvac.dir ~= dir_no then
  165.                     room.nedobre = 1
  166.                     addv(10, "bank-v-flaska")
  167.                 end
  168.                 if lahvac.afaze == 25 then
  169.                     if random(2) == 1 then
  170.                         addm(5, "bank-m-rozbila")
  171.                     end
  172.                 end
  173.                 if room.jej == 0 and (dolni1.zije == -4 and dist(dolni1, small) < 11 or dolni2.zije == -4 and dist(dolni2, small) < 11) then
  174.                     room.jej = 1
  175.                     addm(5, "bank-m-jejda")
  176.                 end
  177.                 if room.pokusy == 0 and (big.X > 32 or big.Y > 17) then
  178.                     room.pokusy = 1
  179.                     if random(3) ~= 1 then
  180.                         addv(10, "bank-v-pokusy"..(1 + random(2)))
  181.                         room.hnerus = 1
  182.                     end
  183.                 end
  184.                 if room.zij == 0 and game_getCycles() > math.floor((10000 - room.kdy - room.kdy2) / 16) then
  185.                     room.zij = 1
  186.                     addv(random(50), "bank-v-zije")
  187.                     room.hnerus = 1
  188.                 end
  189.                 if game_getCycles() == room.kdy then
  190.                     if random(3) == 1 then
  191.                         addv(20, "bank-v-potvory")
  192.                         if random(3) == 1 then
  193.                             room.hnerus = 1
  194.                         end
  195.                     else
  196.                         addm(20, "bank-m-organismy")
  197.                     end
  198.                 end
  199.             end
  200.             if room.hnerus == 1 then
  201.                 if random(5) + room.nerus < 4 then
  202.                     room.nerus = room.nerus + 1
  203.                     addm(10, "bank-m-nerus")
  204.                 end
  205.             end
  206.             room.hnerus = 0
  207.             if game_getCycles() > room.kdy then
  208.                 room.kdy = room.kdy + 1000 + random(10000)
  209.             end
  210.             if game_getCycles() > room.kdy2 then
  211.                 room.kdy2 = room.kdy2 + 1000 + random(10000)
  212.             end
  213.             if math.mod(game_getCycles(), 800) == 777 then
  214.                 switch(random(10)){
  215.                     [1] = function()
  216.                         room.ruk = 0
  217.                     end,
  218.                     [2] = function()
  219.                         room.kouk = 0
  220.                     end,
  221.                     [3] = function()
  222.                         room.mrt = 0
  223.                     end,
  224.                     [4] = function()
  225.                         room.nedobre = 0
  226.                     end,
  227.                     [5] = function()
  228.                         room.jej = 0
  229.                     end,
  230.                     [6] = function()
  231.                         room.kolem = 0
  232.                     end,
  233.                     [7] = function()
  234.                         room.nerus = 0
  235.                     end,
  236.                     [8] = function()
  237.                         room.pokusy = 0
  238.                     end,
  239.                     [9] = function()
  240.                         room.zij = 0
  241.                     end,
  242.                     [0] = function()
  243.                         room.bojidole = 0
  244.                     end,
  245.                 }
  246.             end
  247.         end
  248.     end
  249.  
  250.     -- -------------------------------------------------------------
  251.     local function prog_init_klicka()
  252.         return function()
  253.             klicka.afaze = math.mod(game_getCycles(), 2)
  254.             klicka:updateAnim()
  255.         end
  256.     end
  257.  
  258.     -- -------------------------------------------------------------
  259.     local function prog_init_zataras()
  260.         return function()
  261.             if zataras.dir ~= dir_no then
  262.                 room.nep = 1
  263.             end
  264.         end
  265.     end
  266.  
  267.     -- -------------------------------------------------------------
  268.     local function prog_init_horni1()
  269.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  270.  
  271.         horni1.oci = 0
  272.  
  273.         return function()
  274.             horni1.poloha = 0
  275.             if dolni1.zije > 0 then
  276.                 if xdist(horni1, dolni1) == 0 then
  277.                     horni1.poloha = 3
  278.                 elseif horni1.Y == dolni1.Y then
  279.                     local diffdist = xdist(horni1, dolni1)
  280.                     if 1 <= diffdist and diffdist <= 3 then
  281.                         horni1.poloha = 1
  282.                     elseif -3 <= diffdist and diffdist <= -1 then
  283.                         horni1.poloha = 2
  284.                     end
  285.                 end
  286.             end
  287.             if math.mod(game_getCycles(), 3) == 0 and random(100) < 40 then
  288.                 horni1.oci = random(5)
  289.             end
  290.             if random(100) < 2 then
  291.                 horni1.afaze = 5
  292.             elseif horni1.poloha > 0 then
  293.                 horni1.afaze = horni1.poloha
  294.             else
  295.                 horni1.afaze = horni1.oci
  296.             end
  297.             horni1:updateAnim()
  298.         end
  299.     end
  300.  
  301.     -- -------------------------------------------------------------
  302.     local function prog_init_dolni1()
  303.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  304.  
  305.         dolni1.oci = 0
  306.         dolni1.zije = -99
  307.  
  308.         return function()
  309.             if horni1.X ~= dolni1.X and dolni1.zije == -99 then
  310.                 dolni1.zije = -7
  311.             end
  312.             if dolni1.zije == -99 then
  313.             elseif dolni1.zije <= 0 then
  314.                 dolni1.zije = dolni1.zije + 1
  315.                 dolni1.afaze = 1
  316.             else
  317.                 if math.mod(game_getCycles(), 3) == 0 and random(100) < 40 then
  318.                     dolni1.oci = random(4) + 2
  319.                 end
  320.                 pom1 = horni1.poloha
  321.                 if random(100) < 2 then
  322.                     dolni1.afaze = 1
  323.                 elseif pom1 > 0 then
  324.                     if pom1 == 3 then
  325.                         dolni1.afaze = 3
  326.                     else
  327.                         dolni1.afaze = 3 + pom1
  328.                     end
  329.                 else
  330.                     dolni1.afaze = dolni1.oci
  331.                 end
  332.             end
  333.             dolni1:updateAnim()
  334.         end
  335.     end
  336.  
  337.     -- -------------------------------------------------------------
  338.     local function prog_init_zkum()
  339.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  340.  
  341.         for key, tube in pairs(tubes) do
  342.             tube.glob = random(100) + 10
  343.             tube.afaze = 0
  344.             if random(2) == 0 then
  345.                 tube.glob = -tube.glob
  346.             end
  347.         end
  348.  
  349.         return function()
  350.             for key, tube in pairs(tubes) do
  351.                 if tube.glob > 0 then
  352.                     tube.glob = tube.glob - 1
  353.                     if tube.glob == 0 then
  354.                         tube.glob = -random(100) - 10
  355.                     end
  356.                     if odd(game_getCycles() + key) then
  357.                         if random(2) > 0 then
  358.                             tube.afaze = math.mod(tube.afaze + 1, 3)
  359.                         else
  360.                             tube.afaze = math.mod(tube.afaze + 2, 3)
  361.                         end
  362.                     end
  363.                 else
  364.                     tube.glob = tube.glob + 1
  365.                     if tube.glob == 0 then
  366.                         tube.glob = random(100) + 10
  367.                     end
  368.                     tube.afaze = 0
  369.                 end
  370.                 tube:updateAnim()
  371.             end
  372.         end
  373.     end
  374.  
  375.     -- -------------------------------------------------------------
  376.     local function prog_init_horni2()
  377.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  378.  
  379.         horni2.oci = 0
  380.  
  381.         return function()
  382.             horni2.poloha = 0
  383.             if dolni2.zije > 0 then
  384.                 if xdist(horni2, dolni2) == 0 then
  385.                     horni2.poloha = 3
  386.                 elseif horni2.Y == dolni2.Y then
  387.                     local diffdist = xdist(horni2, dolni2)
  388.                     if 1 <= diffdist and diffdist <= 3 then
  389.                         horni2.poloha = 1
  390.                     elseif -3 <= diffdist and diffdist <= -1 then
  391.                         horni2.poloha = 2
  392.                     end
  393.                 end
  394.             end
  395.             if math.mod(game_getCycles(), 3) == 0 and random(100) < 40 then
  396.                 horni2.oci = random(5)
  397.             end
  398.             if random(100) < 2 then
  399.                 horni2.afaze = 5
  400.             elseif horni2.poloha > 0 then
  401.                 horni2.afaze = horni2.poloha
  402.             else
  403.                 horni2.afaze = horni2.oci
  404.             end
  405.             horni2:updateAnim()
  406.         end
  407.     end
  408.  
  409.     -- -------------------------------------------------------------
  410.     local function prog_init_dolni2()
  411.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  412.  
  413.         dolni2.oci = 0
  414.         dolni2.zije = -99
  415.  
  416.         return function()
  417.             if horni2.X ~= X and dolni2.zije == -99 then
  418.                 dolni2.zije = -7
  419.             end
  420.             if dolni2.zije == -99 then
  421.             elseif dolni2.zije <= 0 then
  422.                 dolni2.zije = dolni2.zije + 1
  423.                 dolni2.afaze = 1
  424.             else
  425.                 if math.mod(game_getCycles(), 3) == 0 and random(100) < 40 then
  426.                     dolni2.oci = random(4) + 2
  427.                 end
  428.                 pom1 = horni2.poloha
  429.                 if random(100) < 2 then
  430.                     dolni2.afaze = 1
  431.                 elseif pom1 > 0 then
  432.                     if pom1 == 3 then
  433.                         dolni2.afaze = 3
  434.                     else
  435.                         dolni2.afaze = 3 + pom1
  436.                     end
  437.                 else
  438.                     dolni2.afaze = dolni2.oci
  439.                 end
  440.             end
  441.             dolni2:updateAnim()
  442.         end
  443.     end
  444.  
  445.     -- -------------------------------------------------------------
  446.     local function prog_init_kostra()
  447.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  448.  
  449.         kostra.citac = random(200) + 200
  450.  
  451.         return function()
  452.             if kostra.afaze < 8 then
  453.                 if kostra.citac == 0 then
  454.                     kostra.afaze = kostra.afaze + 1
  455.                     kostra.citac = random(200) + 200
  456.                 else
  457.                     kostra.citac = kostra.citac - 1
  458.                 end
  459.             end
  460.             kostra:updateAnim()
  461.         end
  462.     end
  463.  
  464.     -- -------------------------------------------------------------
  465.     local function prog_init_oko()
  466.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  467.  
  468.         oko.cinnost = 0
  469.  
  470.         return function()
  471.             local cinnost_table = {
  472.                 [0] = function()
  473.                     if random(100) < 10 then
  474.                         local rand8 = random(8)
  475.                         switch(rand8){
  476.                             [3] = function()
  477.                                 oko.citac = random(3) + 2
  478.                                 oko.cinnost = 2
  479.                                 oko.faze = random(2) * 2
  480.                             end,
  481.                             [7] = function()
  482.                                 oko.citac = random(10) + 2
  483.                                 oko.cinnost = 5
  484.                             end,
  485.                             default = function()
  486.                                 if 0 <= rand8 and rand8 <= 2 then
  487.                                     oko.citac = random(5) + 5
  488.                                     oko.cinnost = 1
  489.                                     oko.faze = random(2) * 2
  490.                                 elseif 4 <= rand8 and rand8 <= 6 then
  491.                                     oko.citac = random(12) + 12
  492.                                     oko.cinnost = 3 + random(2)
  493.                                 end
  494.                             end,
  495.                         }
  496.                     end
  497.                 end,
  498.                 [1] = function()
  499.                     switch(oko.faze){
  500.                         [0] = function()
  501.                             if oko.cinnost == 1 then
  502.                                 oko.afaze = 1
  503.                             else
  504.                                 oko.afaze = 3
  505.                             end
  506.                             if random(100) < 20 then
  507.                                 oko.faze = oko.faze + 1
  508.                             end
  509.                         end,
  510.                         [1] = function()
  511.                             oko.afaze = 0
  512.                             oko.faze = oko.faze + 1
  513.                         end,
  514.                         [2] = function()
  515.                             if oko.cinnost == 1 then
  516.                                 oko.afaze = 2
  517.                             else
  518.                                 oko.afaze = 4
  519.                             end
  520.                             if random(100) < 20 then
  521.                                 oko.faze = oko.faze + 1
  522.                             end
  523.                         end,
  524.                         [3] = function()
  525.                             oko.afaze = 0
  526.                             oko.citac = oko.citac - 1
  527.                             if oko.citac == 0 then
  528.                                 oko.cinnost = 0
  529.                             else
  530.                                 oko.faze = 0
  531.                             end
  532.                         end,
  533.                     }
  534.                 end,
  535.                 [3] = function()
  536.                     switch(oko.cinnost){
  537.                         [3] = function()
  538.                             switch(oko.afaze){
  539.                                 [0] = function()
  540.                                     oko.afaze = random(4) + 1
  541.                                 end,
  542.                                 [1] = function()
  543.                                     oko.afaze = 3
  544.                                 end,
  545.                                 [2] = function()
  546.                                     oko.afaze = 4
  547.                                 end,
  548.                                 [3] = function()
  549.                                     oko.afaze = 2
  550.                                 end,
  551.                                 [4] = function()
  552.                                     oko.afaze = 1
  553.                                 end,
  554.                             }
  555.                         end,
  556.                         [4] = function()
  557.                             switch(oko.afaze){
  558.                                 [0] = function()
  559.                                     oko.afaze = random(4) + 1
  560.                                 end,
  561.                                 [1] = function()
  562.                                     oko.afaze = 4
  563.                                 end,
  564.                                 [2] = function()
  565.                                     oko.afaze = 3
  566.                                 end,
  567.                                 [3] = function()
  568.                                     oko.afaze = 1
  569.                                 end,
  570.                                 [4] = function()
  571.                                     oko.afaze = 2
  572.                                 end,
  573.                             }
  574.                         end,
  575.                         [5] = function()
  576.                             if random(100) < 40 then
  577.                                 oko.afaze = random(5)
  578.                             end
  579.                         end,
  580.                     }
  581.                     oko.citac = oko.citac - 1
  582.                     if oko.citac == 0 then
  583.                         oko.cinnost = 0
  584.                         oko.afaze = 0
  585.                     end
  586.                 end,
  587.             }
  588.  
  589.             cinnost_table[2] = cinnost_table[1]
  590.  
  591.             cinnost_table[4] = cinnost_table[3]
  592.             cinnost_table[5] = cinnost_table[3]
  593.  
  594.             switch(oko.cinnost)(cinnost_table)
  595.             oko:updateAnim()
  596.         end
  597.     end
  598.  
  599.     -- -------------------------------------------------------------
  600.     local function prog_init_qldik1()
  601.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  602.  
  603.         qldik1.afaze = 5
  604.         qldik1.zije = 0
  605.         qldik1.oci = 0
  606.  
  607.         return function()
  608.             if qldik1.dir ~= dir_no then
  609.                 qldik1.zije = 1
  610.             end
  611.             if math.mod(game_getCycles(), 3) == 0 then
  612.                 if qldik1.zije > 0 then
  613.                     if random(100) < 20 then
  614.                         qldik1.oci = random(5)
  615.                     end
  616.                     if random(100) < 4 then
  617.                         qldik1.afaze = 5
  618.                     else
  619.                         qldik1.afaze = qldik1.oci
  620.                     end
  621.                 end
  622.             end
  623.             qldik1:updateAnim()
  624.         end
  625.     end
  626.  
  627.     -- -------------------------------------------------------------
  628.     local function prog_init_qldik2()
  629.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  630.  
  631.         qldik2.afaze = 5
  632.         qldik2.zije = 0
  633.         qldik2.oci = 0
  634.  
  635.         return function()
  636.             if qldik2.dir ~= dir_no then
  637.                 qldik2.zije = 1
  638.             end
  639.             if math.mod(game_getCycles(), 3) == 0 then
  640.                 if qldik2.zije > 0 then
  641.                     if random(100) < 20 then
  642.                         qldik2.oci = random(5)
  643.                     end
  644.                     if random(100) < 4 then
  645.                         qldik2.afaze = 5
  646.                     else
  647.                         qldik2.afaze = qldik2.oci
  648.                     end
  649.                 end
  650.             end
  651.             qldik2:updateAnim()
  652.         end
  653.     end
  654.  
  655.     -- -------------------------------------------------------------
  656.     local function prog_init_qldik3()
  657.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  658.  
  659.         qldik3.oci = 0
  660.         qldik3.skace = 0
  661.  
  662.         return function()
  663.             if math.mod(game_getCycles(), 2) == 0 then
  664.                 if qldik3.skace == 0 then
  665.                     if random(100) < 1 then
  666.                         qldik3.skace = random(7) * 2 + 3
  667.                     end
  668.                     if random(100) < 4 then
  669.                         qldik3.afaze = 5
  670.                     else
  671.                         if random(100) < 30 then
  672.                             qldik3.oci = random(5)
  673.                         end
  674.                         qldik3.afaze = qldik3.oci
  675.                     end
  676.                 else
  677.                     if odd(qldik3.skace) then
  678.                         qldik3.afaze = 6
  679.                     else
  680.                         qldik3.afaze = 7
  681.                     end
  682.                     qldik3.skace = qldik3.skace - 1
  683.                 end
  684.             end
  685.             qldik3:updateAnim()
  686.         end
  687.     end
  688.  
  689.     -- -------------------------------------------------------------
  690.     local function prog_init_lahvac()
  691.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  692.  
  693.         lahvac.rozbit = 0
  694.         lahvac.vnitrek = random(4)
  695.         lahvac.stav = 0
  696.         lahvac.smer = random(2)
  697.         lahvac.pada = 0
  698.  
  699.         return function()
  700.             switch(lahvac.rozbit){
  701.                 [0] = function()
  702.                     if math.mod(game_getCycles(), 4) == 0 then
  703.                         switch(random(4)){
  704.                             [0] = function()
  705.                                 lahvac.vnitrek = math.mod(lahvac.vnitrek + 1, 4)
  706.                             end,
  707.                             [1] = function()
  708.                                 lahvac.vnitrek = math.mod(lahvac.vnitrek + 3, 4)
  709.                             end,
  710.                         }
  711.                     end
  712.                     switch(lahvac.stav){
  713.                         [0] = function()
  714.                             if random(100) < 5 then
  715.                                 lahvac.stav = 10 + random(2) * 10
  716.                                 lahvac.smer = 1 - lahvac.smer
  717.                                 lahvac.afaze = 0
  718.                             elseif random(100) < 7 then
  719.                                 lahvac.stav = 1 + random(2)
  720.                                 lahvac.afaze = 7 + lahvac.stav * 4 + math.mod(lahvac.vnitrek, 2)
  721.                             else
  722.                                 lahvac.afaze = lahvac.vnitrek
  723.                             end
  724.                         end,
  725.                         [3] = function()
  726.                             if random(100) < 7 then
  727.                                 lahvac.stav = 2
  728.                                 lahvac.afaze = 15 + math.mod(lahvac.vnitrek, 2)
  729.                             elseif random(100) < 7 then
  730.                                 lahvac.stav = 4
  731.                                 lahvac.afaze = 22 + math.mod(lahvac.vnitrek, 2)
  732.                             elseif math.mod(lahvac.vnitrek, 2) == 1 and random(100) < 10 then
  733.                                 lahvac.afaze = 19
  734.                             else
  735.                                 lahvac.afaze = 20 + math.mod(lahvac.vnitrek, 2)
  736.                             end
  737.                         end,
  738.                         [4] = function()
  739.                             if random(100) < 7 then
  740.                                 lahvac.stav = 3
  741.                                 lahvac.afaze = 20 + math.mod(lahvac.vnitrek, 2)
  742.                             end
  743.                         end,
  744.                         default = function()
  745.                             if 1 <= lahvac.stav and lahvac.stav <= 2 then
  746.                                 if random(100) < 7 then
  747.                                     lahvac.afaze = 7 + lahvac.stav * 4 + math.mod(lahvac.vnitrek, 2)
  748.                                     lahvac.stav = 0
  749.                                 elseif random(100) < 7 and lahvac.stav == 2 then
  750.                                     lahvac.stav = 3
  751.                                     lahvac.afaze = 19
  752.                                 else
  753.                                     lahvac.afaze = 9 + 4 * lahvac.stav + math.mod(lahvac.vnitrek, 2)
  754.                                     if random(100) < 5 then
  755.                                         lahvac.afaze = lahvac.afaze - 2
  756.                                     end
  757.                                 end
  758.                             elseif 10 <= lahvac.stav and lahvac.stav <= 15 then
  759.                                 if lahvac.smer == 0 then
  760.                                     lahvac.afaze = lahvac.stav - 5
  761.                                 else
  762.                                     lahvac.afaze = 25 - lahvac.stav - 5
  763.                                 end
  764.                                 if lahvac.stav == 15 then
  765.                                     lahvac.stav = 0
  766.                                 else
  767.                                     lahvac.stav = lahvac.stav + 1
  768.                                 end
  769.                             elseif 20 <= lahvac.stav and lahvac.stav <= 25 then
  770.                                 if math.mod(game_getCycles(), 3) == 0 then
  771.                                     if lahvac.smer == 0 then
  772.                                         lahvac.afaze = lahvac.stav - 15
  773.                                     else
  774.                                         lahvac.afaze = 45 - lahvac.stav - 15
  775.                                     end
  776.                                     if lahvac.stav == 25 then
  777.                                         lahvac.stav = 0
  778.                                     else
  779.                                         lahvac.stav = lahvac.stav + 1
  780.                                     end
  781.                                 end
  782.                             end
  783.                         end,
  784.                     }
  785.                     if lahvac.dir == dir_down then
  786.                         lahvac.pada = 1
  787.                     elseif lahvac.pada == 1 then
  788.                         lahvac.rozbit = 1
  789.                     end
  790.                 end,
  791.                 [5] = function()
  792.                     lahvac.stav = random(30) + 30
  793.                     lahvac.rozbit = lahvac.rozbit + 1
  794.                 end,
  795.                 [6] = function()
  796.                     if lahvac.stav == 0 or lahvac.dir == dir_left or lahvac.dir == dir_right then
  797.                         lahvac.rozbit = lahvac.rozbit + 1
  798.                         lahvac.stav = 0
  799.                     else
  800.                         lahvac.stav = lahvac.stav - 1
  801.                     end
  802.                 end,
  803.                 [7] = function()
  804.                     if lahvac.dir ~= dir_no then
  805.                         lahvac.stav = random(10) + 10
  806.                         lahvac.rozbit = 10
  807.                         lahvac.afaze = 31 + random(3)
  808.                     else
  809.                         switch(lahvac.stav){
  810.                             [0] = function()
  811.                                 if random(100) < 7 then
  812.                                     lahvac.stav = 1 + random(2)
  813.                                     if lahvac.stav == 1 then
  814.                                         lahvac.afaze = 28
  815.                                     else
  816.                                         lahvac.afaze = 30
  817.                                     end
  818.                                 else
  819.                                     lahvac.afaze = 27
  820.                                 end
  821.                             end,
  822.                             [1] = function()
  823.                                 if random(100) < 7 then
  824.                                     lahvac.stav = 0
  825.                                     lahvac.afaze = 28
  826.                                 elseif random(100) < 5 then
  827.                                     lahvac.afaze = 28
  828.                                 else
  829.                                     lahvac.afaze = 29
  830.                                 end
  831.                             end,
  832.                             [2] = function()
  833.                                 if random(100) < 7 then
  834.                                     lahvac.stav = 0
  835.                                 end
  836.                             end,
  837.                         }
  838.                     end
  839.                 end,
  840.                 [10] = function()
  841.                     if lahvac.stav == 0 then
  842.                         lahvac.stav = random(10) + 10
  843.                         lahvac.rozbit = 6
  844.                         lahvac.afaze = 27
  845.                     else
  846.                         if odd(game_getCycles()) then
  847.                             if random(2) == 0 then
  848.                                 lahvac.afaze = math.mod(lahvac.afaze - 30, 3) + 31
  849.                             else
  850.                                 lahvac.afaze = math.mod(lahvac.afaze - 29, 3) + 31
  851.                             end
  852.                         end
  853.                         lahvac.stav = lahvac.stav - 1
  854.                     end
  855.                 end,
  856.                 default = function()
  857.                     if 1 <= lahvac.rozbit and lahvac.rozbit <= 4 then
  858.                         lahvac.afaze = 23 + lahvac.rozbit
  859.                         lahvac.rozbit = lahvac.rozbit + 1
  860.                     end
  861.                 end,
  862.             }
  863.             lahvac:updateAnim()
  864.         end
  865.     end
  866.  
  867.     -- -------------------------------------------------------------
  868.     local function prog_init_oka()
  869.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  870.  
  871.         oka.impuls = 0
  872.         oka.kuk = 0
  873.         oka.smer = 4
  874.         local smallActive = true
  875.  
  876.         return function()
  877.             if oka.dir ~= dir_no then
  878.                 if oka.impuls == 0 then
  879.                     oka.faze = 0
  880.                 end
  881.                 oka.impuls = 4
  882.             end
  883.             if oka.impuls > 0 then
  884.                 if oka.faze < oka.impuls then
  885.                     oka.afaze = 7 + oka.faze
  886.                 else
  887.                     oka.afaze = 15 - 2 * oka.impuls + oka.faze
  888.                 end
  889.                 oka.faze = oka.faze + 1
  890.                 if oka.faze == 2 * oka.impuls then
  891.                     oka.faze = 0
  892.                     oka.impuls = oka.impuls - 1
  893.                 end
  894.             elseif oka.kuk > 0 then
  895.                 oka.afaze = 1
  896.                 oka.kuk = oka.kuk - 1
  897.                 oka.smer = 4
  898.             else
  899.                 if big.dir ~= dir_no or not small:isAlive() then
  900.                     smallActive = false
  901.                 elseif small.dir ~= dir_no or not big:isAlive() then
  902.                     smallActive = true
  903.                 end
  904.  
  905.                 if smallActive then
  906.                     pom1 = xdist(small, oka)
  907.                     pom2 = ydist(small, oka)
  908.                 else
  909.                     pom1 = xdist(big, oka)
  910.                     pom2 = ydist(big, oka)
  911.                 end
  912.                 if small:isAlive() or big:isAlive() then
  913.                     if pom1 < 0 then
  914.                         if math.abs(pom1) >= 2 * math.abs(pom2) then
  915.                             oka.novysmer = 6
  916.                         elseif math.abs(pom2) >= 2 * math.abs(pom1) then
  917.                             oka.novysmer = 4
  918.                         else
  919.                             oka.novysmer = 5
  920.                         end
  921.                     else
  922.                         if math.abs(pom1) >= 2 * math.abs(pom2) then
  923.                             oka.novysmer = 2
  924.                         elseif math.abs(pom2) >= 2 * math.abs(pom1) then
  925.                             oka.novysmer = 4
  926.                         else
  927.                             oka.novysmer = 3
  928.                         end
  929.                     end
  930.                 end
  931.                 if oka.smer == -1 then
  932.                     oka.smer = oka.novysmer
  933.                 elseif oka.smer < oka.novysmer then
  934.                     oka.smer = oka.smer + 1
  935.                 elseif oka.smer > oka.novysmer then
  936.                     oka.smer = oka.smer - 1
  937.                 end
  938.                 oka.afaze = oka.smer
  939.                 if random(200) < 1 then
  940.                     oka.kuk = random(4) + 4
  941.                 end
  942.             end
  943.             oka:updateAnim()
  944.         end
  945.     end
  946.  
  947.     -- -------------------------------------------------------------
  948.     local function prog_init_malej()
  949.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  950.  
  951.         malej.houpe = 0
  952.         malej.oci = 0
  953.  
  954.         return function()
  955.             if math.mod(game_getCycles(), 3) == 0 then
  956.                 if random(100) < 10 then
  957.                     malej.oci = random(5)
  958.                 end
  959.             end
  960.             if malej.dir ~= dir_no and malej.houpe == 0 then
  961.                 malej.faze = 0
  962.                 malej.houpe = 1
  963.             end
  964.             switch(malej.houpe){
  965.                 [0] = function()
  966.                     if random(100) < 2 then
  967.                         malej.afaze = 4
  968.                     else
  969.                         malej.afaze = malej.oci
  970.                     end
  971.                 end,
  972.                 [1] = function()
  973.                     malej.faze = malej.faze + 1
  974.                     switch(malej.faze){
  975.                         [1] = function()
  976.                             malej.afaze = 5
  977.                         end,
  978.                         [4] = function()
  979.                             malej.afaze = 6
  980.                         end,
  981.                         [6] = function()
  982.                             if malej.dir == dir_no then
  983.                                 malej.houpe = 0
  984.                                 malej.oci = 0
  985.                             else
  986.                                 malej.faze = 0
  987.                             end
  988.                         end,
  989.                     }
  990.                 end,
  991.             }
  992.             malej:updateAnim()
  993.         end
  994.     end
  995.  
  996.     -- -------------------------------------------------------------
  997.     local function prog_init_ruka()
  998.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  999.  
  1000.         ruka.cinnost = 0
  1001.         ruka.smer = 0
  1002.         ruka.faze = 0
  1003.  
  1004.         return function()
  1005.             if odd(game_getCycles()) then
  1006.                 pomb1 = xdist(ruka, small) == 0 and ydist(ruka, small) > 0 and ydist(ruka, small) < 10
  1007.                 pomb2 = xdist(ruka, big) == 0 and ydist(ruka, big) > 0 and ydist(ruka, big) < 10
  1008.                 if pomb1 and pomb2 then
  1009.                     if small.Y > big.Y then
  1010.                         pomb2 = false
  1011.                     end
  1012.                 end
  1013.                 if pomb1 or pomb2 then
  1014.                     if ruka.cinnost ~= 2 then
  1015.                         ruka.faze = 0
  1016.                     end
  1017.                     ruka.cinnost = 2
  1018.                     if pomb1 then
  1019.                         if small:isLeft() then
  1020.                             ruka.smer = 0
  1021.                         else
  1022.                             ruka.smer = 1
  1023.                         end
  1024.                     elseif big:isLeft() then
  1025.                         ruka.smer = 0
  1026.                     else
  1027.                         ruka.smer = 1
  1028.                     end
  1029.                 elseif ruka.cinnost == 2 then
  1030.                     ruka.cinnost = 0
  1031.                     ruka.faze = 0
  1032.                 end
  1033.                 switch(ruka.cinnost){
  1034.                     [0] = function()
  1035.                         if random(100) < 2 then
  1036.                             ruka.cinnost = 1
  1037.                             ruka.afaze = 0
  1038.                             ruka.faze = (random(3) + 2) * 2
  1039.                         else
  1040.                             if random(100) < 3 then
  1041.                                 ruka.smer = 1 - ruka.smer
  1042.                             end
  1043.                             if ruka.smer == 0 then
  1044.                                 ruka.faze = math.mod(ruka.faze + 1, 7)
  1045.                             else
  1046.                                 ruka.faze = math.mod(ruka.faze + 6, 7)
  1047.                             end
  1048.                             ruka.afaze = ruka.faze
  1049.                         end
  1050.                     end,
  1051.                     [1] = function()
  1052.                         ruka.faze = ruka.faze - 1
  1053.                         if odd(ruka.faze) then
  1054.                             ruka.afaze = 7
  1055.                         else
  1056.                             ruka.afaze = 0
  1057.                         end
  1058.                         if ruka.faze == 0 then
  1059.                             ruka.cinnost = 0
  1060.                         end
  1061.                     end,
  1062.                     [2] = function()
  1063.                         ruka.faze = 1 - ruka.faze
  1064.                         ruka.afaze = 8 + ruka.faze + ruka.smer * 2
  1065.                     end,
  1066.                 }
  1067.             end
  1068.             ruka:updateAnim()
  1069.         end
  1070.     end
  1071.  
  1072.     -- -------------------------------------------------------------
  1073.     local function prog_init_pldicek()
  1074.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  1075.  
  1076.         pldicek.pocet = 0
  1077.         initPldici(pldicek)
  1078.  
  1079.         return function()
  1080.             progPldici(pldicek)
  1081.         end
  1082.     end
  1083.  
  1084.     -- -------------------------------------------------------------
  1085.     local function prog_init_mutant()
  1086.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  1087.  
  1088.  
  1089.         return function()
  1090.             if odd(game_getCycles()) then
  1091.                 if dvere1.dir == dir_no and dvere2.dir == dir_no then
  1092.                     if 0 <= mutant.afaze and mutant.afaze <= 4 then
  1093.                         local rand20 = random(20)
  1094.                         if rand20 == 0 then
  1095.                             mutant.afaze = 5
  1096.                         elseif 1 <= rand20 and rand20 <= 3 then
  1097.                             mutant.afaze = random(5)
  1098.                         end
  1099.                     elseif 5 == mutant.afaze or mutant.afaze == 9 then
  1100.                         if random(4) == 2 then
  1101.                             mutant.afaze = 5 + random(5)
  1102.                         else
  1103.                             local rand20 = random(20)
  1104.                             if 0 <= rand20 and rand20 <= 1 then
  1105.                                 mutant.afaze = random(5)
  1106.                             elseif 2 <= rand20 and rand20 <= 7 then
  1107.                                 mutant.afaze = 6 + random(3)
  1108.                             end
  1109.                         end
  1110.                     end
  1111.                 else
  1112.                     mutant.afaze = 9
  1113.                 end
  1114.             end
  1115.             mutant:updateAnim()
  1116.         end
  1117.     end
  1118.  
  1119.     -- --------------------
  1120.     local update_table = {}
  1121.     local subinit
  1122.     subinit = prog_init_room()
  1123.     if subinit then
  1124.         table.insert(update_table, subinit)
  1125.     end
  1126.     subinit = prog_init_klicka()
  1127.     if subinit then
  1128.         table.insert(update_table, subinit)
  1129.     end
  1130.     subinit = prog_init_zataras()
  1131.     if subinit then
  1132.         table.insert(update_table, subinit)
  1133.     end
  1134.     subinit = prog_init_horni1()
  1135.     if subinit then
  1136.         table.insert(update_table, subinit)
  1137.     end
  1138.     subinit = prog_init_dolni1()
  1139.     if subinit then
  1140.         table.insert(update_table, subinit)
  1141.     end
  1142.     subinit = prog_init_zkum()
  1143.     if subinit then
  1144.         table.insert(update_table, subinit)
  1145.     end
  1146.     subinit = prog_init_horni2()
  1147.     if subinit then
  1148.         table.insert(update_table, subinit)
  1149.     end
  1150.     subinit = prog_init_dolni2()
  1151.     if subinit then
  1152.         table.insert(update_table, subinit)
  1153.     end
  1154.     subinit = prog_init_kostra()
  1155.     if subinit then
  1156.         table.insert(update_table, subinit)
  1157.     end
  1158.     subinit = prog_init_oko()
  1159.     if subinit then
  1160.         table.insert(update_table, subinit)
  1161.     end
  1162.     subinit = prog_init_qldik1()
  1163.     if subinit then
  1164.         table.insert(update_table, subinit)
  1165.     end
  1166.     subinit = prog_init_qldik2()
  1167.     if subinit then
  1168.         table.insert(update_table, subinit)
  1169.     end
  1170.     subinit = prog_init_qldik3()
  1171.     if subinit then
  1172.         table.insert(update_table, subinit)
  1173.     end
  1174.     subinit = prog_init_lahvac()
  1175.     if subinit then
  1176.         table.insert(update_table, subinit)
  1177.     end
  1178.     subinit = prog_init_oka()
  1179.     if subinit then
  1180.         table.insert(update_table, subinit)
  1181.     end
  1182.     subinit = prog_init_malej()
  1183.     if subinit then
  1184.         table.insert(update_table, subinit)
  1185.     end
  1186.     subinit = prog_init_ruka()
  1187.     if subinit then
  1188.         table.insert(update_table, subinit)
  1189.     end
  1190.     subinit = prog_init_pldicek()
  1191.     if subinit then
  1192.         table.insert(update_table, subinit)
  1193.     end
  1194.     subinit = prog_init_mutant()
  1195.     if subinit then
  1196.         table.insert(update_table, subinit)
  1197.     end
  1198.     return update_table
  1199. end
  1200. local update_table = prog_init()
  1201.  
  1202.  
  1203. -- -----------------------------------------------------------------
  1204. -- Update
  1205. -- -----------------------------------------------------------------
  1206. function prog_update()
  1207.     for key, subupdate in pairs(update_table) do
  1208.         subupdate()
  1209.     end
  1210. end
  1211.  
  1212.